package com.kyh.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;

public class RequestFilterUtil {
	
	private static final Logger logger = Logger.getLogger(RequestFilterUtil.class);
	
	public static String verifyManage(HttpServletRequest request){
		
		// 验证token_
		String token_ = request.getHeader("token-");
		if(token_ == null || token_.length() < 1){
			return "无效的请求";
		}
		
		// 验证adminid
		String adminidStr = token_.substring(0, token_.indexOf('_'));
		if (adminidStr == null || "".equals(adminidStr)) {
			return "账号已在其它地方登录";
		}
		Long adminid = Long.parseLong(adminidStr);
		
		// 获取服务器存放的token
		String tokenServer = "xxx";
		
		logger.debug("url=====" + request.getRequestURL().toString());
		logger.debug("token_=====" + token_);
		logger.debug("tokenServer=====" + tokenServer);
		
		// 验证签名一致
		if (token_.equals(adminidStr + "_" + tokenServer)) {
			return "success";
		} else {
			return "签名有误";
		}
	}
	
}
